package com.shanzhu.beadhouse.controller;

import com.shanzhu.beadhouse.common.constant.Constant;
import com.shanzhu.beadhouse.entity.base.Result;
import com.shanzhu.beadhouse.entity.query.BedManageQuery;
import com.shanzhu.beadhouse.entity.query.OperateBedQuery;
import com.shanzhu.beadhouse.service.BedManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "床铺管理")
@RestController
@RequestMapping("/bedManage")
// @PreAuthorize("@AuthorityAssert.hasAuthority('/live/bedManage')") // 临时注释权限检查
public class BedManageController {
    @Resource
    private BedManageService bedManageService;

    @PostMapping("/pageBedByKey")
    @ApiOperation(value = "分页查询床位列表", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result pageBedByKey(@ApiParam(value = "分页查询床位请求实体", required = true) @RequestBody BedManageQuery query,
                               @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.pageBedByKey(query);
    }

    @GetMapping("/listIdleBeds")
    @ApiOperation(value = "获取空闲床位列表", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result listIdleBeds(@ApiParam(value = "老人ID（可选，用于调换床位时包含当前床位）", required = false) @RequestParam(required = false) Long elderId,
                               @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.listIdleBeds(elderId);
    }



    @PostMapping("/editBed")
    @ApiOperation(value = "编辑床位信息", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result editBed(@ApiParam(value = "操作床位请求实体", required = true) @RequestBody OperateBedQuery query,
                          @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.editBed(query);
    }



    @GetMapping("/getBedById")
    @ApiOperation(value = "获取床位详情", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result getBedById(@ApiParam(value = "床位ID", required = true) @RequestParam Long bedId,
                             @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.getBedById(bedId);
    }

    @GetMapping("/listRooms")
    @ApiOperation(value = "获取房间列表", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result listRooms(@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.listRooms();
    }

    @GetMapping("/listBuildings")
    @ApiOperation(value = "获取楼栋列表", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result listBuildings(@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.listBuildings();
    }

    @GetMapping("/listFloors")
    @ApiOperation(value = "获取楼层列表", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result listFloors(@ApiParam(value = "楼栋ID", required = false) @RequestParam(required = false) Long buildingId,
                             @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.listFloors(buildingId);
    }

    @GetMapping("/listRoomTypes")
    @ApiOperation(value = "获取房间类型列表", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result listRoomTypes(@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.listRoomTypes();
    }

    @GetMapping("/listBedStatus")
    @ApiOperation(value = "获取床位状态列表", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result listBedStatus(@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.listBedStatus();
    }

    @GetMapping("/listElders")
    @ApiOperation(value = "获取老人列表", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result listElders(@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.listElders();
    }

    @PostMapping("/unassignBed")
    @ApiOperation(value = "解除床位分配", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
    public Result unassignBed(@ApiParam(value = "床位ID", required = true) @RequestParam Long bedId,
                              @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
        return bedManageService.unassignBed(bedId);
    }
} 